package com.ghh.app.monsterrush.monsters;

import java.util.Arrays;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.ghh.app.monsterrush.MonsterActor;
import com.ghh.app.monsterrush.MonsterRushGame;
import com.ghh.app.monsterrush.StateAction;
import com.ghh.app.monsterrush.monsters.state.AttackedState;
import com.ghh.app.monsterrush.monsters.state.DestroyState;
import com.ghh.app.monsterrush.monsters.state.WalkingState;

public class Slime extends MonsterActor {
	private static final int	columns		= 4;
	private static final int	rows		= 2;

	private final static int	basic_life	= 60;
	private final static float	basic_speed	= -60f;

	private Texture				texture;
	private TextureRegion[][]	all_frames;

	public Slime(MonsterRushGame game) {
		super(game, basic_life, basic_speed);
		setSize(getTexture().getWidth() / columns, getTexture().getHeight() / rows);
	}

	private TextureRegion[][] getAllFrames() {
		if (all_frames == null) {
			Texture tx = getTexture();
			all_frames = TextureRegion.split(tx, tx.getWidth() / columns, tx.getHeight() / rows);
		}
		return all_frames;
	}

	private Texture getTexture() {
		if (texture == null) {
			texture = new Texture(Gdx.files.internal("slime.png"));
		}
		return texture;
	}

	@Override
	protected StateAction createWalkState() {
		TextureRegion[] frames = Arrays.copyOfRange(getAllFrames()[0], 0, 4);
		return new WalkingState(this, frames, 0.25f);
	}

	@Override
	protected StateAction createAttackedState() {
		TextureRegion[] frames = Arrays.copyOfRange(getAllFrames()[1], 0, 2);
		return new AttackedState(this, frames, 0.25f);
	}

	@Override
	protected StateAction createDestroyState() {
		TextureRegion[] frames = Arrays.copyOfRange(getAllFrames()[1], 2, 4);
		return new DestroyState(this, frames, 0.25f);
	}

	@Override
	public void dispose() {
		texture.dispose();
	}
}
